package com.xisoft.bx.ctrl.bill;

import com.xisoft.bx.service.billService.BillAppService;
import com.xisoft.utils.ErrorMessage;
import com.xisoft.utils.PubResult;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 作者：*****
 * @create 创建时间：20220802
 * @update 修改时间：20220802
 */
@Log4j2
@RestController
@RequestMapping("/AppBill")
public class BillCtrl {

    @Autowired
    private BillAppService service;

    @ResponseBody
    @RequestMapping(value = "/Save", method = RequestMethod.POST)
    public PubResult Save(@RequestBody String jsonStr) throws Exception {
        log.info("调用BillCtrl的Save方法：" + jsonStr);

        if (StringUtils.isEmpty(jsonStr)) {
            throw new Exception(ErrorMessage.PARAM_IS_NULL_OR_EMPTY.getDesc());
        }
        PubResult result = new PubResult();
        try {
            result = service.businessBillSave(JSONObject.parseObject(jsonStr));
        } catch (Exception e) {
            log.error("调用BillCtrl的Save方法：" + e.toString());
            throw new Exception(e.getMessage());
        }
        return result;
    }

    @ResponseBody
    @RequestMapping(value = "/Delete", method = RequestMethod.POST)
    public PubResult Delete(@RequestBody String jsonStr) throws Exception {
        log.info("调用BillCtrl的Delete方法：" + jsonStr);

        if (StringUtils.isEmpty(jsonStr)) {
            throw new Exception(ErrorMessage.PARAM_IS_NULL_OR_EMPTY.getDesc());
        }
        PubResult result = new PubResult();
        try {
            result = service.businessBillDelete(JSONObject.parseObject(jsonStr));
        } catch (Exception e) {
            log.error("调用BillCtrl的Delete方法：" + e.toString());
            throw new Exception(e.getMessage());
        }
        return result;
    }

    @ResponseBody
    @RequestMapping(value = "/Update", method = RequestMethod.POST)
    public PubResult Update(@RequestBody String jsonStr) throws Exception {
        log.info("调用BillCtrl的Update方法：" + jsonStr);

        if (StringUtils.isEmpty(jsonStr)) {
            throw new Exception(ErrorMessage.PARAM_IS_NULL_OR_EMPTY.getDesc());
        }
        PubResult result = new PubResult();
        try {
            result = service.businessBillUpdate(JSONObject.parseObject(jsonStr));
        } catch (Exception e) {
            log.error("调用BillCtrl的Update方法：" + e.toString());
            throw new Exception(e.getMessage());
        }
        return result;
    }

    @ResponseBody
    @RequestMapping(value = "/Query", method = RequestMethod.POST)
    public PubResult Query(@RequestBody String jsonStr) throws Exception {
        log.info("调用BillCtrl的Query方法：" + jsonStr);

        if (StringUtils.isEmpty(jsonStr)) {
            throw new Exception(ErrorMessage.PARAM_IS_NULL_OR_EMPTY.getDesc());
        }
        PubResult result = new PubResult();
        try {
            result = service.businessBillQuery(JSONObject.parseObject(jsonStr));
        } catch (Exception e) {
            log.error("调用BillCtrl的Query方法：" + e.toString());
            throw new Exception(e.getMessage());
        }
        return result;
    }

    @ResponseBody
    @RequestMapping(value = "/QueryConfig", method = RequestMethod.POST)
    public PubResult QueryConfig(@RequestBody String jsonStr) throws Exception {
        log.info("调用BillCtrl的QueryConfig方法：" + jsonStr);
        if (StringUtils.isEmpty(jsonStr)) {
            throw new Exception(ErrorMessage.PARAM_IS_NULL_OR_EMPTY.getDesc());
        }
        PubResult result = new PubResult();
        try {
            result = service.businessBillConfig(JSONObject.parseObject(jsonStr));
        } catch (Exception e) {
            log.error("调用BillCtrl的QueryConfig方法：" + e.toString());
            throw new Exception(e.getMessage());
        }
        return result;
    }

    @ResponseBody
    @RequestMapping(value = "/DataSource", method = RequestMethod.POST)
    public PubResult queryDataSources(@RequestBody String jsonStr) throws Exception {
        log.info("调用BillCtrl的DataSource方法：" + jsonStr);
        if (StringUtils.isEmpty(jsonStr)) {
            throw new Exception(ErrorMessage.PARAM_IS_NULL_OR_EMPTY.getDesc());
        }
        PubResult result = new PubResult();
        try {
            result = service.businessDataSourcesQuery(JSONObject.parseObject(jsonStr));
        } catch (Exception e) {
            log.error("调用BillCtrl的DataSource方法：" + e.toString());
            throw new Exception(e.getMessage());
        }
        return result;
    }
}
